package mytest.wd2;

import cn.hutool.core.lang.hash.Hash;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.gson.Gson;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import pojo.Circulation;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class Test10 {
    public static void main(String[] args) {
        String message = "{\"userInfo\":\"8062346668766\",\"userInfoType\":\"phone\",\"vendor\":\"nigeria\",\"bizType\":\"alendr\",\"flag\":\"pre_credit_test\",\"extra\":{\"batchId\":\"73ac9f4f-cc90-471f-aadb-7ee2d2c0d24a\",\"createTime\":\"1732796845463\"}}";
        Map<String, Object> map = toMap(message);
        Map extra = MapUtils.getMap(map, "extra");
        String json = new Gson().toJson(new HashMap<>());
        System.out.println(json);
    }


    private static final ObjectMapper mapper = new ObjectMapper();

    static {
        //Do not throw an error when converting empty objects to json
        mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
        //Allow attribute names without quotes
        mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
        // allow single quotes
        mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
        // When setting the input, ignore attributes that exist in the json string but are not actually in the java object
        mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
        //Set the style that includes attributes when outputting
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    }

    public static Map<String, Object> toMap(String json) {
        if (StringUtils.isBlank(json)) {
            return null;
        }

        try {
            return mapper.readValue(json, new TypeReference<Map<String, Object>>() {
            });
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
    }
}